home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / satan-1.1.1 / bin / ypbind.satan < prev   
Text File  |  1996-04-24  |  2KB  |  74 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # Try to identify a host's NIS domain name and NIS server by trying out a
  4. # series of NIS domain name guesses. When the number of guesses becomes
  5. # sufficiently large (say, several tens when the network is fast) the
  6. # remote ypbind daemon may fall behind so far that it runs out of file
  7. # descriptors.  This can be fixed by inserting sleep() calls.
  8.  
  9. $running_under_satan = 1;
  10.  
  11. require 'config/paths.pl';
  12. require 'perl/fix_hostname.pl';
  13. require 'perl/misc.pl';
  14. require 'perllib/getopts.pl';
  15.  
  16. #
  17. # Do JCL stuff.
  18. #
  19. $usage="Usage: $0 target [hints]\n";
  20. &Getopts("d:v");
  21.  
  22. if ($#ARGV < 0) {
  23.     print STDERR $usage;
  24.     exit 1;
  25. }
  26. $target = $ARGV[0];
  27. $service = &basename($0, ".satan");
  28. $status = "a";
  29.  
  30. # Iterate over all hints. For each hint, try the hint itself, then all
  31. # results from breaking it up at successive dots. We use an associative
  32. # array to weed out duplicate guesses.
  33. #
  34. if ($opt_d) {
  35.     $guesses{$opt_d} = 0;
  36. } else {
  37.     foreach $i (1..$#ARGV, 0) {
  38.     $hint = $ARGV[$i];
  39.     $guesses{$hint} = 0;
  40.     for ($dot = rindex($hint,"."); $dot >= $[; $dot = rindex($head,".")) {
  41.         $head = substr($hint, $[, $dot - $[);
  42.         $guesses{$head} = 0;
  43.         $tail = substr($hint, $dot + 1);
  44.         $guesses{$tail} = 0;
  45.     }
  46.     }
  47. }
  48.  
  49. foreach $guess (keys %guesses) {
  50.     if (defined($opt_v)) {
  51.     print STDERR "ypbind.satan: trying: $guess\n";
  52.     }
  53.     open (YPWHICH, "$YPWHICH -d $guess $target 2>/dev/null|") 
  54.     || exit 1;
  55.     while (<YPWHICH>) {
  56.     chop;
  57.     $nis_server = &fix_hostname(&get_host_name($_), $target);
  58.     $severity = "x";
  59.     $trusted = "root\@$nis_server";
  60.     $trustee = "root\@$target";
  61.     $service_output = "$guess $nis_server";
  62.     $text = "$nis_server serves nis domain $guess for $target";
  63.     &satan_print();
  64.     exit;
  65.     }
  66.     close (YPWHICH);
  67. }
  68.  
  69. # All out guesses failed.
  70.  
  71. $text = "unable to guess nis domain name of $target";
  72. &satan_print();
  73. exit;
  74.